package com.example.service.webhook.business.alipay.repository;

import com.example.service.webhook.business.alipay.entity.AlipayBankInfoEntity;
import com.example.service.webhook.business.alipay.entity.AlipayJieBeiEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author liyang
 * @email liyang@51dojo.com
 * @create 2017-11-03 上午10:10
 * @description 支付宝借呗crud
 **/
@Repository
public class AlipayJieBeiRepository extends BaseDAO<AlipayJieBeiEntity>{
    @Resource(name="templateAlipay")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void saveJieBei(AlipayJieBeiEntity entity) throws Exception  {
        entity.setCreateTime(DateUtil.getCurrentDate());
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.add(entity);
    }


    public void updateJieBei(AlipayJieBeiEntity entity) throws Exception  {
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.modify(entity);
    }


    public AlipayJieBeiEntity getJieBei(String userId,String mappingId) throws Exception {
        String sql = "";
        String tableName = "t_alipay_jiebei";
        sql = "select * from " + tableName + " where userId=? and mappingId=?";
        AlipayJieBeiEntity pojo = null;
        try{
            pojo = (AlipayJieBeiEntity) queryOne(sql, new Object[] {userId,mappingId}, new AlipayJieBeiEntity());
        }catch(EmptyResultDataAccessException e){
            return null;
        }

        return pojo;
    }
}
